<?php
/*
Template Name: event-list
*/

get_header();

// sub view of main view to display single posts or alternate lists.
$subview = get_query_var('event_subview');

switch (get_query_var('event_view'))
{
	case "previews":
		$args['post_type'] = 'tribe_events';
		
		if ($subview != '') {
			$args['eventDisplay'] = $subview;
			query_posts($args);
		} else {
			$args['eventDisplay'] = 'upcoming';
			query_posts($args);
			if (!have_posts()) {
				$args['eventDisplay'] = 'past';
				query_posts($args);
			}
		}
		
		wts_header_events('preview');		
		if (have_posts()) :
			include (TEMPLATEPATH . '/events/list-loop.php');
		else :
			if (tribe_is_upcoming()) {
				echo 'No upcoming events.';
				echo !empty($is_cat_message) ? $is_cat_message : ".";
			} elseif (tribe_is_past()) {
				echo 'No previous events.';
				echo !empty($is_cat_message) ? $is_cat_message : ".";
			}		
		endif; ?>
		<div id="tribe-events-nav-below" class="tribe-events-nav clearfix">
	
			<div class="tribe-events-nav-previous"><?php 
			// Display Previous Page Navigation
			if( tribe_is_upcoming() && get_previous_posts_link() ) : ?>
				<?php previous_posts_link( '<span>'.__('&laquo; Previous Events', 'tribe-events-calendar').'</span>' ); ?>
			<?php elseif( tribe_is_upcoming() && !get_previous_posts_link( ) ) : ?>
				<a href='<?php echo tribe_get_past_link(); ?>'><span><?php _e('&laquo; Previous Events', 'tribe-events-calendar' ); ?></span></a>
			<?php elseif( tribe_is_past() && get_next_posts_link( ) ) : ?>
				<?php next_posts_link( '<span>'.__('&laquo; Previous Events', 'tribe-events-calendar').'</span>' ); ?>
			<?php endif; ?>
			</div>
	
			<div class="tribe-events-nav-next"><?php
			// Display Next Page Navigation
			if( tribe_is_upcoming() && get_next_posts_link( ) ) : ?>
				<?php next_posts_link( '<span>'.__('Next Events &raquo;', 'tribe-events-calendar').'</span>' ); ?>
			<?php elseif( tribe_is_past() && get_previous_posts_link( ) ) : ?>
				<?php previous_posts_link( '<span>'.__('Next Events &raquo;', 'tribe-events-calendar').'</span>' ); // a little confusing but in 'past view' to see newer events you want the previous page ?>
			<?php elseif( tribe_is_past() && !get_previous_posts_link( ) ) : ?>
				<a href='<?php echo tribe_get_upcoming_link(); ?>'><span><?php _e('Next Events &raquo;', 'tribe-events-calendar'); ?></span></a>
			<?php endif; ?>
			</div>
	
		</div>
		<?php
		break;
		
	case "reviews":
		$args = array(
			'category_name' => 'events'
		);
		query_posts($args);
		
		if (have_posts()) :
			wts_header_events('review');
			include (TEMPLATEPATH . '/articles-loop.php');
		endif;
		break;
		
	case "gallery":
		$args = array(
			'category_name' => 'events-gallery'
		);
		query_posts($args);
		if (have_posts()) :
			wts_header_events('gallery');		
			include(TEMPLATEPATH . '/articles-loop.php');
		endif;
		break;
		
	default:
		$display404 = TRUE;
}
if (isset($display404) && $display404 == TRUE) {
	include(TEMPLATEPATH . '/404.php');
}

get_footer();